package com.ruoyi.web.service.zkService.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.web.controller.common.CustomException;
import com.ruoyi.web.domain.Category;
import com.ruoyi.web.domain.Dish;
import com.ruoyi.web.mapper.CategoryMapper;
import com.ruoyi.web.service.zkService.DishService;
import com.ruoyi.web.service.zkService.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

@Autowired
    private DishService dishService;

public void remove(Long id){
    LambdaQueryWrapper<Dish> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dish::getCategoryId,id);
    int count = (int) dishService.count(queryWrapper);

    if(count>0){
        throw new CustomException("当前分类下关联了菜品，不能删除");
    }

}

}
